<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2018/5/18
  Time: 8:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <%@include file="/styles/common/cssStyle.jsp" %>
</head>
<body>
<div class="mt-20">
<div class="btn-group ">
    <button class="btn " style="background: #00B83F" onclick="add('用户新增','<%=basePath%>role/addUser','800','500')">添加人员</button>
    <button class="btn " style="background: #00a2d4" onclick="edit('用户修改','<%=basePath%>role/toupdateUser','null','800','500')">修改人员</button>
    <button class="btn " style="background: #cc0000" onclick="del()">删除人员</button>
    <button class="btn " style="background: #fcc900" onclick="stop()">停用</button>
</div>
<div class="mt-20">
<table  class="table table-striped  table-bordered table-hover table-condensed success" >
    <tr>
        <td></td>
        <td>用户名</td>
        <td>密码</td>
        <td>头像</td>
        <td>姓名</td>
        <td>性别</td>
        <td>生日</td>
        <td>电话</td>
        <td>是否停用</td>
    </tr>
    <c:forEach items="${userList}" var="u">
        <tr>
            <td><input type="checkbox" name="test" value="${u.id}"/></td>
            <td >${u.username}</td>
            <td>${u.password}</td>
            <td><img alt="暂无图片" src="<%=basePath%>${u.head}" style="height:50px;width: 50px;"></td>
            <td id="name${u.id}">${u.name}</td>
            <td> ${u.sex=="1"?'男':'女'}</td>
            <td>${u.brithday}</td>
            <td>${u.phone}</td>
            <td>
               ${u.disable=="1"?'<font color="green">正常</font>':'<font color="red">已停用</font>'}
            </td>

        </tr>
    </c:forEach>

</table>

</body>
<%@include file="/styles/common/jsStyle.jsp"%>
<script type="text/javascript">
    // 添加
    function add(title,url,w,h){
        layer_show(title,url,w,h);
    }
    //修改
    function edit(title,url,UsersId,w,h){
        var UsersId =[];
        $('input[name="test"]:checked').each(function(){
            UsersId.push($(this).val());
        });
        if(UsersId.length==0){
            alert("你还没有选择任何内容！")
        }else{
            if(UsersId.length==2){
                alert("只能选择一条数据！")
            }else {

                url = url + "?UsersId="+ UsersId;
                layer_show(title,url,w,h);
            }

        }
    }
      /*  alert(UsersId.length==0 ?'你还没有选择任何内容！':UsersId);*/
//删除
        function del(){
            var UsersId =[];
            $('input[name="test"]:checked').each(function(){
                UsersId.push($(this).val());
            });
           if(UsersId.length==0){
                alert("你还没有选择任何内容！")

            }else{
                   layer.confirm("确定要删除吗?",function(index){
                        var UsersId =[];
                        $('input[name="test"]:checked').each(function(){
                            UsersId.push($(this).val());
                        });

                          var url = "<%=basePath%>role/deleteUser?UsersId="+UsersId;

                        $.post(url,UsersId,function(result){
                            if(result == "1"){
                                layer.msg('已删除!',{icon:1,time:1000});
                                location.href="<%=basePath%>role/todelete";
                            }else{
                                layer.msg('删除失败!',{icon:1,time:1000});
                            }
                    });
                   })
           }
        }
//停用
    function stop(){
        var userId =[];
        $('input[name="test"]:checked').each(function(){
            userId.push($(this).val());
        });
            if(""!=userId && null!=userId){
                var realName=$("#name"+userId).text();
                layer.confirm("确定要停用  <span style='color:red'>" + realName + "</span>  人员吗?",function(index){
                    $.post(
                        "<%=basePath%>role/stop?userId="+userId,
                        {userId:userId},
                        function(msg){
                            if(msg){
                                layer.msg('已停用!',{icon:1,time:1000});
                                location.href="<%=basePath%>role/todelete";
                            }else{
                                layer.msg('操作失败!',{icon:1,time:1000});
                            }
                        },"json"
                    )
                });
            }else{
                layer.msg('请选择要停用的人员!',{time:2000});
            }
    }

</script>
</html>
